GINO Graphics Suite - GINO v9.0    

2D Interpolation

GINO provides a facility to interpolate user suppled data or from previously drawn curves, lines or arcs using the above point storage mechanism. Passing a single data value with a set of 2D data points, the function gInterpolateData2D() can return all the intersections of the two using linear interpolation.

The function has the following form:

nint=gInterpolateData2D(nopt, ptint, npts, points2, nptout, ptout1)

where nopt can be GXDATA or GYDATA indicating the interpretation of the argument ptint, the value to be interpreted. The argument npts specifies the number of 2D data points supplied in the array points2 (which is of type GPOINT) and nptout is the size of the output array ptout1.

The function returns the number of intersection points returned in the array ptout1. Where nopt=GXDATA this array will contain Y values and where nopt=GYDATA this array will contain X values. There may be zero, one or more than one depending on the form of the data, but it will never exceed nptout even though there may be more intersections possible from the supplied data.

The following example shows the interpolation of a 2D curve:

[C/C++]
#include <gino-c.h>
#define NP 9
#define NVERT 1000
#define NPOLY 2
#define NPTOUT 4
GPOLYGON poly[NPOLY];
GPOINT   points[NVERT];
GPOINT   data[NP] = { 20.0, 20.0,  35.0,110.0,  50.0,115.0,
                      65.0,110.0,  80.0, 30.0,  95.0, 25.0,
                     110.0, 25.0, 140.0, 40.0, 170.0,120.0 };
float xmin = 10.0;
float xmax = 180.0;
float ptout[NPTOUT];

#if defined(MWIN) || defined(WOGL)
int PASCAL WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
%%%%%% LPSTR lpszCmdParam, int nCmdShow)
#else
int main ()
#endif
{
   float ptint;
   int npt,npol,n,ninter,ntemp;

/*  Initialise GINO and point storage */

   gOpenGino();
   xxxxx();
   gSetWorkspaceLimit(2000);
   gDefinePointWorkspace(1000);

/*  Draw curve and store points internally */

   gMoveTo2D(data[0].x,data[0].y);
   gSetLineColour(GRED);
   gSetPointMode(GSPACE);
   gDrawAkimaTo2D(NP,data,GNONE,GNONE);
   gSetPointMode(GOFF);
/*  Retrieve stored curve points */

   n=gReturnInternalPoints2D(NVERT,points,NPOLY,poly,&npt,&npol);

/*  Calculate intersections through interpolation */

   ptint=45.0;
   ninter=gInterpolateData2D(GYDATA,ptint,npt,points,NPTOUT,ptout);

/*  Show intersection points on the curve */

   gSetLineColour(GGREEN);
   gMoveTo2D(xmin,ptint);
   gDrawLineTo2D(xmax,ptint);
   for (ntemp=0;ntemp<ninter;ntemp++) {
      gMoveTo2D(ptout[ntemp],ptint);
      gDrawMarker(GSTAR);
   }

   gSuspendDevice();
   gCloseGino();
}
[F90]
use gino_f90
parameter (NP=9,NVERT=1000,NPOLY=2,NPTOUT=4)
type (GPOLYGON) poly(NPOLY)
type (GPOINT) points(NVERT)
type (GPOINT)  :: data(NP) = (/ &
   GPOINT( 20.0, 20.0), GPOINT( 35.0,110.0), GPOINT( 50.0,115.0), &
   GPOINT( 65.0,110.0), GPOINT( 80.0, 30.0), GPOINT( 95.0, 25.0), &
   GPOINT(110.0, 25.0), GPOINT(140.0, 40.0), GPOINT(170.0,120.0) /)
real :: xmin = 10.0
real :: xmax = 180.0
real ptout(NPTOUT)
!
!  Initialise GINO and point storage
!
   call gOpenGino
   call xxxxx
   call gSetWorkspaceLimit(1,2000)
   call gDefinePointWorkspace(1000)
!
!  Draw curve and store points internally
!
   call gMoveTo2D(data(1)%x,data(1)%y)
   call gSetLineColour(GRED)
   call gSetPointMode(GSPACE)
   call gDrawAkimaTo2D(NP,data,GNONE,GNONE)
   call gSetPointMode(GOFF)
!
!  Retrieve stored curve points
!
   n=gReturnInternalPoints2D(NVERT,points,NPOLY,poly,npt,npol)
!
!  Calculate intersections through interpolation
!
   ptint=45.0
   ninter=gInterpolateData2D(GYDATA,ptint,npt,points,NPTOUT,ptout)
!
!  Show intersection points on the curve
!
   call gSetLineColour(GGREEN)
   call gMoveTo2D(xmin,ptint)
   call gDrawLineTo2D(xmax,ptint)
   do ntemp = 1, ninter
      call gMoveTo2D(ptout(ntemp),ptint)
      call gDrawMarker(GSTAR)
   end do
!
   call gSuspendDevice
   call gCloseGino
stop
end

Data Interpolation